package com.workspace.js_website.mapper;

import com.workspace.js_website.bean.Role;
import org.apache.ibatis.annotations.Insert;
import org.apache.ibatis.annotations.Mapper;
import org.apache.ibatis.annotations.Select;
import org.springframework.stereotype.Repository;

import java.util.List;

/**
 * 用户角色表相关数据库操作
 */

@Mapper
@Repository("rolesMapper")
public interface RolesMapper {
    @Select("select r.* from roles r, roles_user ru where r.role_id = ru.role_id and ru.user_id = #{uid}")
    List<Role> getRolesByUid(String uid);

    @Select("select role_id from roles where rolename = #{Role}")
    int getIdByRole(String Role);

    @Insert("insert into roles_user(user_id, role_id) values(#{userid}, #{roleid})")
    void addRoles(int roleid, String userid);
}
